package yc.day0110;



import yc.day0109.lottery.dao.UserDao;
import yc.day0109.lottery.dao.impl.UserDaoImpl;
import yc.day0109.lottery.po.User;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JstlDemoServlet extends HttpServlet {
    @Override
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        //设置中文字符乱码，解决request/reponse响应
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        //1.使用多态体现，创建实例化UserDao数据访问层
        UserDao userDao = new UserDaoImpl();
        //2.创建Map集合对象，用来存储查询列表的搜索条件参数
        Map<String,Object> map = new HashMap<>();
        //2.1 获取indexController.jsp中存储在request作用域中的searchName
        String searchName = request.getAttribute("searchName") == null ? "" : String.valueOf(request.getAttribute("searchName"));
        if (!"".equals(searchName)) {
            map.put("markNo", searchName);
        }
        //3.调用查询列表方法
        List<User> userList = userDao.queryUserByType(map);
        //使用jsp提供的EL表达式和jstl标签库简化jsp页面中的JavaBean
        request.setAttribute("userList",userList);
        request.getRequestDispatcher("jsp//yc//day0110//jstl_demo.jsp").forward(request,response);

    }
}
